package swd.work.generator.v2.java.bean;

import java.io.*;
import java.util.*;

import com.pub.database.*;
import com.pub.tools.PublicFunction;

import swd.work.generator.v2.java.base.*;

public class BusinessBean extends BeanExtend implements BeanImplement {

    public BusinessBean(QueryBean pqbnDAO, String pstrUserNO) throws Exception {
        super(pqbnDAO, pstrUserNO);
    }

    /**
     * combindSQLWhere
     *
     * @param pstbSQL StringBuffer
     * @param pstrDbfNO String
     * @return StringBuffer
     */
    private StringBuffer combindSQLWhere(StringBuffer pstbSQL, String pstrDbfNO) {
        ArrayList<ArrayList<Object>> laltWKF_LAYOUT = null;
        //ArrayList laltWKF_FRM1 = null;

        try {
            //以wkf_layout所記錄的key fld組合 where 條件式
            laltWKF_LAYOUT = gqbnDAO.querySQL(
                    "select fld_no,fld_kind from wkf_layout where dbf_no='" +
                    pstrDbfNO + "' and is_key='Y'");

            for (int i = 0; i < laltWKF_LAYOUT.size(); i++) {
                pstbSQL.append(((ArrayList<Object>) laltWKF_LAYOUT.get(i)).get(0).
                               toString());
                pstbSQL.append("=");

                //判斷欄位型態
                if (((ArrayList<Object>) laltWKF_LAYOUT.get(i)).get(1).toString().
                    equals("C")) {
                    pstbSQL.append("'\"");
                } else if (((ArrayList<Object>) laltWKF_LAYOUT.get(i)).get(1).toString().
                           equals("N")) {
                    pstbSQL.append("\"");
                }
                /*
                                 laltWKF_FRM1 = gqbnDAO.querySQL(
                        "select fld_no from wkf_frm1 where prg_no='" +
                        pstrPrgNO +
                        "' and frm_no='" + pstrFrmNO + "' and fld_no='" +
                        ((ArrayList) laltWKF_LAYOUT.get(i)).get(0).toString() +
                 "' and seqno=(select min(seqno) from wkf_frm1 where prg_no='" +
                        pstrPrgNO + "' and frm_no='" + pstrFrmNO +
                        "' and fld_no='" +
                        ((ArrayList) laltWKF_LAYOUT.get(i)).get(0).toString() +
                        "')");
                 */
                pstbSQL.append(" + view.get");
                pstbSQL.append(((ArrayList<Object>) laltWKF_LAYOUT.get(i)).get(0).
                               toString().substring(0,1).toUpperCase() + ((ArrayList<Object>) laltWKF_LAYOUT.get(i)).get(0).
                               toString().substring(1));
                pstbSQL.append("()");

                if (((ArrayList<Object>) laltWKF_LAYOUT.get(i)).get(1).toString().
                    equals("C")) {
                    pstbSQL.append(" + \"'\"");
                }

                if (i < (laltWKF_LAYOUT.size() - 1)) {
                    pstbSQL.append(" + \" and ");
                }
            }
            return pstbSQL;
        } catch (Exception e) {
            e.printStackTrace();
            return pstbSQL;
        }
    }

    /**
     * outputCheckNotNullFld
     *
     * @param pbwrPrgNO BufferedWriter
     */
    private void outputCheckNotNullFld(BufferedWriter pbwrPrgNO,
                                       String pstrPrgNO) throws Exception {
        Hashtable<String,Hashtable<String,Object>> lhtTableFld = null;
        int lintFldCount = 0;
        String lstrFldNO = null;
        String lstrFldKind = null;
        String lstrNotNullCndt=null;

        try {
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "/**", 2);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "* 此Method主要是在新增存檔前要做欄位必填的檢查",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @param view", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*/", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "String checkNotNullFld(View view) throws Exception{",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "StringBuffer lstbNullFldList=new StringBuffer();",
                                 1);

            lhtTableFld = gqbnDAO.hashtableSQL(
                    "select fld_no,max(fld_kind) as max_fld_kind,max(not_null_cndt) as max_not_null_cndt from wkf_frm1 where exists(select * from wkf_frm0 where prg_no='" +
                    pstrPrgNO + "' and record_kind='S' and wkf_frm0.prg_no=wkf_frm1.prg_no and wkf_frm0.frm_no=wkf_frm1.frm_no) and fld_no is not null and not_null_cndt is not null group by fld_no");

            while (lhtTableFld != null &&
                   lhtTableFld.get(String.valueOf(lintFldCount)) != null) {

                lstrFldNO = ((Hashtable<String,Object>) lhtTableFld.get(String.valueOf(
                        lintFldCount))).get("FLD_NO").toString();
                lstrFldKind = ((Hashtable<String,Object>) lhtTableFld.get(String.valueOf(
                        lintFldCount))).get("MAX_FLD_KIND").toString();
                lstrNotNullCndt = ((Hashtable<String,Object>) lhtTableFld.get(String.valueOf(
                        lintFldCount))).get("MAX_NOT_NULL_CNDT").toString();
                lintFldCount++;

                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                     "if(" + lstrNotNullCndt +"){lstbNullFldList.append(view.get" +
                                     lstrFldNO.substring(0,1).toUpperCase() + lstrFldNO.substring(1) + "()==" +
                                     (lstrFldKind.equals("N") ? "0" : "null") +
                                     " ? view.get" + lstrFldNO +
                                     "Title() + \",\" : \"\");}",
                                     1);
            }

            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "return (lstbNullFldList.toString().equals(\"\") ? \"\" : lstbNullFldList.delete(lstbNullFldList.length()-1,lstbNullFldList.length()).toString());",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "}",
                                 1);

        } catch (Exception e) {
            throw new Exception(e.toString());
        } finally {
            if (lhtTableFld != null) {
                lhtTableFld.clear();
                lhtTableFld = null;
            }
        }
    }

    /**
     * outputClassVarible
     *
     * @param pbwrPrgNO BufferedWriter
     */
    private void outputClassVarible(BufferedWriter pbwrPrgNO) throws Exception {
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                             "QueryBean gqbnDAO=null;", 1);
    }

    /**
     * outputDefaultConstructor
     *
     * @param pbwrPrgNO BufferedWriter
     */
    private void outputConstructor(BufferedWriter pbwrPrgNO) throws Exception {
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                             "public Business(QueryBean pqbnDAO){", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                             "gqbnDAO=pqbnDAO;", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
    }

    private void outputExeInsSQLMethod(BufferedWriter pbwrPrgNO,
                                       String pstrPrgNO) {
        Hashtable<String,Hashtable<String,Object>> lhtWKF_FRM0 = null;
        Hashtable<String,Hashtable<String,Object>> lhtWKF_FRM1 = null;
        Hashtable<String,Object> lhtWKF_FRM0_DATA = null;
        Hashtable<String,Object> lhtWKF_FRM1_DATA = null;
        int lintWKF_FRM0_cnt = 0;
        int lintWKF_FRM1_cnt = 0;
        StringBuffer lstbInsSQL = new StringBuffer();

        try {
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "/**", 2);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "* 此Method主要是產生INSERT主檔SQL敘述，並透過QueryBean執行",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @param view", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*/", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "String exeInsSQL(View view) throws Exception{",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "String lstrSQL=new String();", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "Vector lvtrParam=new Vector();", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "try{", 1);

            lhtWKF_FRM0 = gqbnDAO.hashtableSQL(
                    "select frm_no,dbf_no from wkf_frm0 where prg_no='" +
                    pstrPrgNO +
                    "' and record_kind='S'");

            while (lhtWKF_FRM0 != null &&
                   lhtWKF_FRM0.get(String.valueOf(lintWKF_FRM0_cnt)) != null) {
                lhtWKF_FRM0_DATA = (Hashtable<String,Object>) lhtWKF_FRM0.get(String.valueOf(
                        lintWKF_FRM0_cnt));
                lintWKF_FRM0_cnt++;
                /*
                                 lhtWKF_FRM1 = gqbnDAO.hashtableSQL("select Max(wkf_frm1.frm_no) AS frm_no_max, Max(wkf_frm1.seqno) AS seqno_max, Max(wkf_frm1.rw_mode) AS rw_mode_max, wkf_frm1.fld_no from wkf_frm1 GROUP BY wkf_frm1.fld_no, wkf_frm1.prg_no HAVING (((Max(wkf_frm1.frm_no)) In (select frm_no from wkf_frm0 where prg_no='" +
                 pstrPrgNO + "' and dbf_no='" +
                 lhtWKF_FRM0_DATA.get("DBF_NO") +
                 "')) AND (exists (select fld_no from wkf_layout where dbf_no='" +
                 lhtWKF_FRM0_DATA.get("DBF_NO") +
                 "' and fld_no=wkf_frm1.fld_no)) AND ((wkf_frm1.prg_no)='" +
                                                   pstrPrgNO + "'))");*/


                lhtWKF_FRM1 = gqbnDAO.hashtableSQL(
                        "select fld_no,fld_kind,(select nvl(wide_dec,'0') from wkf_layout where dbf_no=(select dbf_no from wkf_frm0 where wkf_frm0.prg_no=wkf_frm1.prg_no and wkf_frm0.frm_no=wkf_frm1.frm_no) and wkf_layout.fld_no=wkf_frm1.fld_no) as wide_dec_z from wkf_frm1 where prg_no='" +
                        pstrPrgNO + "' and frm_no='" +
                        lhtWKF_FRM0_DATA.get("FRM_NO") +
                        "' and (exists(select * from wkf_layout where dbf_no='" +
                        lhtWKF_FRM0_DATA.get("DBF_NO") +
                        "' and fld_no=wkf_frm1.fld_no))");

                lintWKF_FRM1_cnt = 0;

                lstbInsSQL.delete(0, lstbInsSQL.length());
                lstbInsSQL.append("insert into ");

                while (lhtWKF_FRM1 != null &&
                       lhtWKF_FRM1.get(String.valueOf(lintWKF_FRM1_cnt)) != null) {
                    lhtWKF_FRM1_DATA = (Hashtable<String,Object>) lhtWKF_FRM1.get(String.
                            valueOf(
                                    lintWKF_FRM1_cnt));
                    lintWKF_FRM1_cnt++;

                    if (lhtWKF_FRM1_DATA.get("FLD_KIND").equals("D")) {
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "lvtrParam.add((view.get" +
                                             lhtWKF_FRM1_DATA.get("FLD_NO").toString().substring(0,1).toUpperCase() + lhtWKF_FRM1_DATA.get("FLD_NO").toString().substring(1) +
                                             "()==null ? null : PublicFunction.getTimestempDate(view.get" +
                                             lhtWKF_FRM1_DATA.get("FLD_NO").toString().substring(0,1).toUpperCase() + lhtWKF_FRM1_DATA.get("FLD_NO").toString().substring(1) +
                                             "())));", 1);
                    } else if (lhtWKF_FRM1_DATA.get("FLD_KIND").equals("N")) {
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "lvtrParam.add((view.get" +
                                             lhtWKF_FRM1_DATA.get("FLD_NO").toString().substring(0,1).toUpperCase() + lhtWKF_FRM1_DATA.get("FLD_NO").toString().substring(1)  +
                                             "()==0 ? null : " +
                                             getParseToObjectSyntax(
                                lhtWKF_FRM1_DATA.get("FLD_KIND").toString(),
                                lhtWKF_FRM1_DATA.get("WIDE_DEC_Z").toString()) +
                                             "(view.get" +
                                             lhtWKF_FRM1_DATA.get("FLD_NO").toString().substring(0,1).toUpperCase() + lhtWKF_FRM1_DATA.get("FLD_NO").toString().substring(1)  +
                                             "())));", 1);
                    } else {
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "lvtrParam.add((view.get" +
                                             lhtWKF_FRM1_DATA.get("FLD_NO").toString().substring(0,1).toUpperCase() + lhtWKF_FRM1_DATA.get("FLD_NO").toString().substring(1)  +
                                             "()==null ? null : view.get" +
                                             lhtWKF_FRM1_DATA.get("FLD_NO").toString().substring(0,1).toUpperCase() + lhtWKF_FRM1_DATA.get("FLD_NO").toString().substring(1)  +
                                             "()));", 1);
                    }
                    if (lintWKF_FRM1_cnt == 1) {
                        lstbInsSQL.append(lhtWKF_FRM0_DATA.get("DBF_NO"));
                        lstbInsSQL.append("(");
                    }

                    lstbInsSQL.append(lhtWKF_FRM1_DATA.get("FLD_NO").toString());

                    if (lhtWKF_FRM1.get(String.valueOf(lintWKF_FRM1_cnt)) != null) {
                        lstbInsSQL.append(",");
                    } else {
                        lstbInsSQL.append(") values");

                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "lstrSQL=\"" +
                                             lstbInsSQL.toString() +
                                             DBFunction.
                                             addQuemark(lstbInsSQL.toString()) +
                                             "\";", 1);

                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "if(!gqbnDAO.executeSQL(lstrSQL,lvtrParam)){;",
                                             1);
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "return \"" +
                                             lhtWKF_FRM0_DATA.get("DBF_NO") +
                                             "\";",
                                             1);
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "}",
                                             1);
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "lvtrParam.clear();",
                                             1);
                        pbwrPrgNO.newLine();
                    }
                }
            }

            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "return \"\";", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "catch(Exception e){", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "e.printStackTrace();", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "throw new Exception(e);", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "finally{",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "lvtrParam.clear();", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (lhtWKF_FRM0 != null) {
                lhtWKF_FRM0.clear();
                lhtWKF_FRM0 = null;
            }
            if (lhtWKF_FRM1 != null) {
                lhtWKF_FRM1.clear();
                lhtWKF_FRM1 = null;
            }
            if (lhtWKF_FRM0_DATA != null) {
                lhtWKF_FRM0_DATA.clear();
                lhtWKF_FRM0_DATA = null;
            }
            if (lhtWKF_FRM1_DATA != null) {
                lhtWKF_FRM1_DATA.clear();
                lhtWKF_FRM1_DATA = null;
            }
        }
    }

    private void outputExeUpdSQLMethod(BufferedWriter pbwrPrgNO,
                                       String pstrPrgNO) {
        Hashtable<String,Hashtable<String,Object>> lhtWKF_FRM0 = null;
        Hashtable<String,Hashtable<String,Object>> lhtWKF_FRM1 = null;
        Hashtable<String,Object> lhtWKF_FRM0_DATA = null;
        Hashtable<String,Object> lhtWKF_FRM1_DATA = null;
        int lintWKF_FRM0_cnt = 0;
        int lintWKF_FRM1_cnt = 0;
        StringBuffer lstbUpdSQL = new StringBuffer();

        try {
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "/**", 2);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "* 此Method主要執行update sql更新主檔，依table schema primary key組成where 條件式",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @param view", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*/", 1);

            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "String exeUpdSQL(View view) throws Exception{", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "String lstrSQL=new String();", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "Vector lvtrParam=new Vector();", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "try{", 1);

            lhtWKF_FRM0 = gqbnDAO.hashtableSQL(
                    "select dbf_no from wkf_frm0 where prg_no='" + pstrPrgNO +
                    "' and record_kind='S' group by dbf_no");

            while (lhtWKF_FRM0 != null &&
                   lhtWKF_FRM0.get(String.valueOf(lintWKF_FRM0_cnt)) != null) {
                lhtWKF_FRM0_DATA = (Hashtable<String,Object>) lhtWKF_FRM0.get(String.valueOf(
                        lintWKF_FRM0_cnt));
                lintWKF_FRM0_cnt++;

                lhtWKF_FRM1 = gqbnDAO.hashtableSQL("select Max(wkf_frm1.rw_mode) AS rw_mode_max, wkf_frm1.fld_no,wkf_frm1.fld_kind,nvl(wkf_layout.wide_dec,'0') as wide_dec_z " +
                        "from wkf_frm1,wkf_frm0,wkf_layout " +
                        "where wkf_frm1.prg_no='" + pstrPrgNO + "' and wkf_frm0.prg_no=wkf_frm1.prg_no and wkf_frm0.frm_no=wkf_frm1.frm_no and wkf_frm0.dbf_no=wkf_layout.dbf_no and wkf_frm1.fld_no=wkf_layout.fld_no " +
                        "GROUP BY wkf_frm1.fld_no,wkf_frm1.fld_kind,wkf_layout.wide_dec HAVING (((Max(wkf_frm1.frm_no)) In (select frm_no from wkf_frm0 where prg_no='" +
                        pstrPrgNO + "' and dbf_no='" +
                        lhtWKF_FRM0_DATA.get("DBF_NO") +
                        "')) AND (exists (select fld_no from wkf_layout where dbf_no='" +
                        lhtWKF_FRM0_DATA.get("DBF_NO") +
                        "' and fld_no=wkf_frm1.fld_no)))");

                lintWKF_FRM1_cnt = 0;

                lstbUpdSQL.delete(0, lstbUpdSQL.length());
                lstbUpdSQL.append("update ");

                while (lhtWKF_FRM1 != null &&
                       lhtWKF_FRM1.get(String.valueOf(lintWKF_FRM1_cnt)) != null) {
                    lhtWKF_FRM1_DATA = (Hashtable<String,Object>) lhtWKF_FRM1.get(String.
                            valueOf(
                                    lintWKF_FRM1_cnt));
                    lintWKF_FRM1_cnt++;

                    super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                         "lvtrParam.add(" +
                                         (getFldType(lhtWKF_FRM1_DATA.get(
                            "FLD_KIND").toString(),
                            lhtWKF_FRM1_DATA.get("WIDE_DEC_Z").toString()).
                                          equals("String") ? "view.get" +
                                         lhtWKF_FRM1_DATA.get("FLD_NO").
                                         toString().substring(0,1).toUpperCase() + lhtWKF_FRM1_DATA.get("FLD_NO").
                                         toString().substring(1) +
                                         "()==null ? null :" : "") +
                                         getParseToObjectSyntax(
                                                 lhtWKF_FRM1_DATA.get(
                            "FLD_KIND").toString(),
                                                 lhtWKF_FRM1_DATA.get(
                            "WIDE_DEC_Z").toString()) +
                                         "(view.get" +
                                         lhtWKF_FRM1_DATA.get("FLD_NO").
                                         toString().substring(0,1).toUpperCase() + lhtWKF_FRM1_DATA.get("FLD_NO").
                                         toString().substring(1) +
                                         "()));", 1);

                    if (lintWKF_FRM1_cnt == 1) {
                        lstbUpdSQL.append(lhtWKF_FRM0_DATA.get("DBF_NO"));
                        lstbUpdSQL.append(" set ");
                    }

                    lstbUpdSQL.append(lhtWKF_FRM1_DATA.get("FLD_NO").toString());

                    if (lhtWKF_FRM1.get(String.valueOf(lintWKF_FRM1_cnt)) != null) {
                        lstbUpdSQL.append("=?,");
                    } else {
                        lstbUpdSQL.append("=? where ");
                        combindSQLWhere(lstbUpdSQL,
                                        lhtWKF_FRM0_DATA.get("DBF_NO").toString());
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "lstrSQL=\"" + lstbUpdSQL.toString() +
                                             ";", 1);
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "if(!gqbnDAO.executeSQL(lstrSQL,lvtrParam)){",
                                             1);
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "return \"" + lhtWKF_FRM0_DATA.get("DBF_NO").toString() + "\";",
                                             1);
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "}",
                                             1);
                    }
                }
            }

            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "return \"\";", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "catch(Exception e){", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "e.printStackTrace();", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "throw new Exception(e.toString());", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "finally{",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "lvtrParam.clear();", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(lhtWKF_FRM0!=null){lhtWKF_FRM0.clear();}
            if(lhtWKF_FRM1!=null){lhtWKF_FRM1.clear();}
            if(lhtWKF_FRM0_DATA!=null){lhtWKF_FRM0_DATA.clear();}
            if(lhtWKF_FRM1_DATA!=null){lhtWKF_FRM1_DATA.clear();}

            lhtWKF_FRM0 = null;
            lhtWKF_FRM1 = null;
            lhtWKF_FRM0_DATA = null;
            lhtWKF_FRM1_DATA = null;
        }
    }

    /**
     * outputSetDataToFld
     *
     * @param pbwrPrgNO BufferedWriter
     */
    private void outputSelectTableDataToFld(BufferedWriter pbwrPrgNO,
                                            String pstrPrgNO) {
        Hashtable<String,Hashtable<String,Object>> lhtWKF_FRM1 = null;
        ArrayList<ArrayList<Object>> laltTableList = null;
        int lintWKF_FRM1_cnt = 0;
        StringBuffer lstbSelSQL = new StringBuffer();
        //String lstrFldNO=null;

        try {
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "/**", 2);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "* 此Method主要是依primary key讀取主檔資料後，將值塞入對應的view.setter",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @param view", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*/", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "String selectTableDataToFld(View view) throws Exception {",
                                 1);

            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "String lstrSQL=null;",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "Hashtable lhtTableData=null;",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "try{", 1);

            laltTableList = gqbnDAO.querySQL(
                    "select dbf_no from wkf_frm0 where prg_no='" + pstrPrgNO +
                    "' group by dbf_no");



            //產生query sql 並依table schema所設定的primary key組成where
            for (int i = 0; i < laltTableList.size(); i++) {
                lhtWKF_FRM1 = gqbnDAO.hashtableSQL("select fld_no,fld_kind,nvl(wide_dec,'0') as wide_dec_z from wkf_layout where exists(select * from wkf_frm1 where wkf_frm1.fld_no=wkf_layout.fld_no and wkf_frm1.prg_no='" +
                        pstrPrgNO + "') and wkf_layout.dbf_no='" +
                        ((ArrayList<Object>) laltTableList.get(i)).get(0).toString() +
                        "' group by fld_no,fld_kind,nvl(wide_dec,'0')");

                lstbSelSQL.delete(0, lstbSelSQL.length());
                lstbSelSQL.append("select ");

                lintWKF_FRM1_cnt = 0;

                while (lhtWKF_FRM1 != null &&
                       lhtWKF_FRM1.get(String.valueOf(lintWKF_FRM1_cnt)) != null) {
                    lstbSelSQL.append(((Hashtable<String,Object>) lhtWKF_FRM1.get(String.
                            valueOf(lintWKF_FRM1_cnt))).get("FLD_NO").toString());

                    lintWKF_FRM1_cnt++;

                    if (lhtWKF_FRM1.get(String.valueOf(lintWKF_FRM1_cnt)) == null) {
                        lstbSelSQL.append(" from ");
                        lstbSelSQL.append(((ArrayList<Object>) laltTableList.get(i)).
                                          get(0).toString());
                        lstbSelSQL.append(" where ");
                        combindSQLWhere(lstbSelSQL,
                                        ((ArrayList<Object>) laltTableList.get(i)).get(
                                                0).toString());
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "lstrSQL=\"" + lstbSelSQL.toString() +
                                             ";",
                                             1);
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "lhtTableData=gqbnDAO.readSingleRowData(lstrSQL);",
                                             1);
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "if(lhtTableData==null){",
                                             1);
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "return \"查無資料\";",
                                             1);
                        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                             "}",
                                             1);

                    } else {
                        lstbSelSQL.append(",");
                    }
                }

                //產生view.setter
                lintWKF_FRM1_cnt = 0;

                while (lhtWKF_FRM1 != null &&
                       lhtWKF_FRM1.get(String.valueOf(lintWKF_FRM1_cnt)) != null) {
                    lstbSelSQL.append(((Hashtable<String,Object>) lhtWKF_FRM1.get(String.
                            valueOf(lintWKF_FRM1_cnt))).get("FLD_NO").toString());

                    super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                         "view.set" +
                                         ((Hashtable<String,Object>) lhtWKF_FRM1.get(String.
                            valueOf(lintWKF_FRM1_cnt))).get("FLD_NO").toString().substring(0,1).toUpperCase() + ((Hashtable<String,Object>) lhtWKF_FRM1.get(String.
                            valueOf(lintWKF_FRM1_cnt))).get("FLD_NO").toString().substring(1) +
                                         "(" +
                                         getParseSyntax((((Hashtable<String,Object>)
                            lhtWKF_FRM1.get(String.
                                            valueOf(lintWKF_FRM1_cnt))).get(
                            "FLD_KIND").toString().equals("D") ? "C" : ((Hashtable<String,Object>)
                            lhtWKF_FRM1.get(String.
                                            valueOf(lintWKF_FRM1_cnt))).get(
                            "FLD_KIND").toString()
),
                            ((Hashtable<String,Object>) lhtWKF_FRM1.get(String.
                            valueOf(lintWKF_FRM1_cnt))).get("WIDE_DEC_Z").
                            toString()) +
                                         "((lhtTableData.get(\"" +
                                         ((Hashtable<String,Object>) lhtWKF_FRM1.get(String.
                            valueOf(lintWKF_FRM1_cnt))).get("FLD_NO").
                                         toString().toUpperCase() +
                                         "\").toString())));",
                                         1);
                    lintWKF_FRM1_cnt++;
                }
            }

            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "return \"\";", 2);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "catch(Exception e){", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "throw new Exception(e.toString());", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "finally{",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "lhtTableData.clear();", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "lhtTableData=null;", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
            //lhtTableData
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * outputSetInitValueForAdd
     *
     * @param pbwrPrgNO BufferedWriter
     */
    private void outputSetInitValueForAdd(BufferedWriter pbwrPrgNO,
                                          String pstrPrgNO) throws Exception {
        Hashtable<String,Hashtable<String,Object>> lhtTableFld = null;
        int lintFldCount = 0;
        String lstrFldNO = null;
        String lstrInitValue = null;

        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "/**", 2);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                             "* 此Method主要是當按下新增後要初始化那些欄位值",
                             1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @param view", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*/", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                             "void setInitValueForAdd(View view) throws Exception{",
                             1);
        try {

            lhtTableFld = gqbnDAO.hashtableSQL("select init_value,fld_no from wkf_frm1 where init_value is not null and exists(select * from wkf_frm0 where prg_no='" +
                                               pstrPrgNO + "' and record_kind='S' and wkf_frm0.prg_no=wkf_frm1.prg_no and wkf_frm0.frm_no=wkf_frm1.frm_no) and fld_no is not null order by to_number(seqno)");

            while (lhtTableFld != null &&
                   lhtTableFld.get(String.valueOf(lintFldCount)) != null) {

                lstrFldNO = ((Hashtable<String,Object>) lhtTableFld.get(String.valueOf(
                        lintFldCount))).get("FLD_NO").toString();
                lstrInitValue = ((Hashtable<String,Object>) lhtTableFld.get(String.valueOf(
                        lintFldCount))).get("INIT_VALUE").toString();

                lintFldCount++;

                //System.out.println(tranFieldVar(lstrInitValue, pstrPrgNO));

                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                     "view.set" + lstrFldNO.substring(0,1).toUpperCase() + lstrFldNO.substring(1) + "(" +
                                     super.
                                     tranPublicVar("\"" + super.tranFieldVar(
                                             lstrInitValue + "\"",
                                             pstrPrgNO)) + ");",
                                     1);
            }

        } catch (Exception e) {
            throw new Exception(e);
        } finally {
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
            if (lhtTableFld != null) {
                lhtTableFld.clear();
                lhtTableFld = null;
            }
        }
    }

    /**
     * outputSetReadonlyForAdd
     *
     * @param pbwrPrgNO BufferedWriter
     */
    /*
    private void outputSetReadonlyForAdd(BufferedWriter pbwrPrgNO,
                                         String pstrPrgNO) throws
            Exception {
        Hashtable lhtWKF_FRM1 = null;
        String lstrFldNO = null;

        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                             "void setReadonlyForAdd(View view) throws Exception{",
                             1);
        try {

            lhtWKF_FRM1 = gqbnDAO.hashtableSQL(
                    "select fld_no from wkf_frm1 where prg_no='" + pstrPrgNO +
                    "' and readonly_yn='Y'");

            if (lhtWKF_FRM1 == null || lhtWKF_FRM1.get("0") == null) {
                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                     "}", 1);
                return;
            }

            for (int i = 0; i < lhtWKF_FRM1.size(); i++) {
                lstrFldNO = ((Hashtable) lhtWKF_FRM1.get(String.valueOf(i))).
                            get("FLD_NO").toString();

                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                     "view.set" + lstrFldNO +
                                     "_readonly(true);", 1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception(e);
        } finally {
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
            if (lhtWKF_FRM1 != null) {
                lhtWKF_FRM1.clear();
                lhtWKF_FRM1 = null;
            }
        }
    }*/

    public String createBean(String pstrPrgNO) {
        String lstrCreateResult = "";
        String lstrBeanFileName = "Business.java";
        BufferedWriter lbwrPrgNO = null;

        try {
            super.setBaseVarible(pstrPrgNO);
            lbwrPrgNO = super.getFwrPrgNO(lstrBeanFileName, "JSP_FRAME_PATH",
                                          "\\com\\swd\\" +
                                          super.getSysNO(gstrUserNO) +
                                          "\\" + pstrPrgNO + "\\", gstrUserNO);

            super.outputBeanHeader(lbwrPrgNO, super.getSysNO(gstrUserNO),
                                   pstrPrgNO, lstrBeanFileName, gstbTabStr,
                                   gstrTabChar);



            //output classify varible
            outputClassVarible(lbwrPrgNO);

            //output Contructor
            outputConstructor(lbwrPrgNO);

            outputGetDataMethod(lbwrPrgNO);

            outputActionForInitMethod(lbwrPrgNO);

            outputActionForEndMethod(lbwrPrgNO);

            outputActionForButtonMethod(lbwrPrgNO,pstrPrgNO);

            outputSetButtonShowMethod(lbwrPrgNO, pstrPrgNO);

            outputSetReadOnlyFieldsMethod(lbwrPrgNO, pstrPrgNO);

            outputSetShowFieldsMethod(lbwrPrgNO, pstrPrgNO);

            //out set value to page field method
            outputSelectTableDataToFld(lbwrPrgNO, pstrPrgNO);

            //output update method 簽核/新增/外掛
            if(super.gstrPrgKind.equals("Y") || super.gstrPrgKind.equals("D") || super.gstrPrgKind.equals("K")){
                outputExeUpdSQLMethod(lbwrPrgNO, pstrPrgNO);//輸出update sql
                outputCheckNotNullFld(lbwrPrgNO, pstrPrgNO);//輸出檢查必填欄位
            }

            //output insert method 新增/外掛
            if(super.gstrPrgKind.equals("D") || super.gstrPrgKind.equals("K")){
                outputExeInsSQLMethod(lbwrPrgNO, pstrPrgNO);//輸出insert sql
                outputSetInitValueForAdd(lbwrPrgNO, pstrPrgNO);//輸出新增起始設定
            }

            //outputSetReadonlyForAdd(lbwrPrgNO, pstrPrgNO);

            //output class end single
            super.outputJavaCode(lbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                lbwrPrgNO.flush();
                lbwrPrgNO.close();
                lbwrPrgNO = null;
            } catch (Exception e) {
                System.out.println("cant flush Business.java File!!");
                e.printStackTrace();
            }  
        }
        
        return lstrCreateResult;
    }

    /**
     * outputSetShowFieldsMethod
     *
     * @param pbwrPrgNO BufferedWriter
     * @param pstrPrgNO String
     */
    private void outputSetShowFieldsMethod(BufferedWriter pbwrPrgNO,
                                           String pstrPrgNO) throws Exception{
        //Hashtable lhtFldShowInfo=null;
        //String lstrFldName=null;
        //String lstrFldShowCndt=null;

        try{
            //lhtFldShowInfo=gqbnDAO.hashtableSQL("select fld_no,fld_hidden_cndt from wkf_frm1 where prg_no='" + pstrPrgNO + "'");

            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "/**", 2);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "* 此Method主要是以prgAction and prgStatus 的值決定那些欄位要隱藏",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "* 此Method可以回傳javascript 語法，透過ajax呼叫後，再透過eval動態執行",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "* 也可以直接在此以view.setXXX_show('none')，希望就算是某些站別要隱藏欄位都是寫在這兒，而不要寫在flow.app20Action etc.,",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @param view", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*/", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "void setShowFields(View view, String pstrPrgAction, String pstrPrgStatus) throws Exception {",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "StringBuffer lstbScript=new StringBuffer();",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "//基本上Alic是不允許有動態控制開關的情況，但若真需要用到時，希望能將code寫在此",1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "//lstbScript.append(\"document.all.item('td_flow_num').style.display='none'\");",1);

            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "//下面這三行是當page load or submit的情況下，依條件直接決定那些欄位要隱藏的sample code",1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "//if(view.getStatus().equals(\"20\") && view.getPrgAction().equals(\"approve\")){",1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "//view.setXXX_show(\"'none'\");",1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "//}",1);


            //super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "return lstbScript.toString();",
            //                     1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
        }
        catch(Exception e){
            throw new Exception(e.toString() + " in BusinessBean.outputSetReadOnlyFieldsMethod");
        }
    }

    /**
     * outputSetReadOnlyFieldsMethod
     *
     * @param pbwrPrgNO BufferedWriter
     * @param pstrPrgNO String
     */
    private void outputSetReadOnlyFieldsMethod(BufferedWriter pbwrPrgNO,
                                               String pstrPrgNO) throws Exception{
        Hashtable<String,Hashtable<String,Object>> lhtFldReadonlyInfo=null;
        String lstrFldName=null;
        String lstrFldReadonlyCndt=null;

        try{
            lhtFldReadonlyInfo=gqbnDAO.hashtableSQL("select fld_no,protect_cndt from wkf_frm1 where prg_no='" + pstrPrgNO + "' and protect_cndt is not null");

            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "/**", 2);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "* 此Method主要是以prgAction and prgStatus 的值決定那些欄位為唯讀",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @param view", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*/", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "void setReadonlyFields(View view, String pstrPrgAction, String pstrPrgStatus) throws Exception {",
                                 1);

            if(lhtFldReadonlyInfo!=null && lhtFldReadonlyInfo.size()>0){
                for (int i = 0; i < lhtFldReadonlyInfo.size(); i++) {
                    lstrFldName = ((Hashtable<String,Object>) lhtFldReadonlyInfo.get(String.valueOf(i))).
                                  get("FLD_NO").toString();
                    lstrFldReadonlyCndt = ((Hashtable<String,Object>) lhtFldReadonlyInfo.get(String.
                            valueOf(i))).get("PROTECT_CNDT").toString();

                    super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                         "view.set" +
                                         lstrFldName.substring(0, 1).toUpperCase() +
                                         lstrFldName.substring(1) + "_readonly(" +
                                         lstrFldReadonlyCndt + " ? \"\" : \"none\");",
                                         1);
                }
            }

            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
        }
        catch(Exception e){
            throw new Exception(e.toString() + " in BusinessBean.outputSetReadOnlyFieldsMethod");
        }
        finally{
            if(lhtFldReadonlyInfo!=null){
                lhtFldReadonlyInfo.clear();
                lhtFldReadonlyInfo=null;
            }
        }
    }

    /**
     * outputSetButtonShowMethod
     *
     * @param pbwrPrgNO BufferedWriter
     */
    private void outputSetButtonShowMethod(BufferedWriter pbwrPrgNO,String pstrPrgNO) throws Exception{
        Hashtable<String,Hashtable<String,Object>> lhtWKF_PRG_BUTTON=null;
        String lstrBtnName=null;
        String lstrBtnShowCndt=null;

        try{
            lhtWKF_PRG_BUTTON=gqbnDAO.hashtableSQL("select special_name_e,action_cndt from wkf_prg_button where prg_no='" + pstrPrgNO + "'");

            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "/**", 2);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                 "* 此Method主要是以prgAction and prgStatus 的值決定要開關那些button",
                                 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @param view", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*/", 1);
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "void setButtonShow(View view, String pstrPrgAction, String pstrPrgStatus) throws Exception {",
                                 1);

            //需有設定button
            if(lhtWKF_PRG_BUTTON!=null && lhtWKF_PRG_BUTTON.size()>0){
                for (int i = 0; i < lhtWKF_PRG_BUTTON.size(); i++) {
                    lstrBtnName = ((Hashtable<String,Object>) lhtWKF_PRG_BUTTON.get(String.valueOf(i))).get(
                            "SPECIAL_NAME_E").toString();
                    lstrBtnShowCndt = ((Hashtable<String,Object>) lhtWKF_PRG_BUTTON.get(String.valueOf(i))).get(
                            "ACTION_CNDT").toString();

                    super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar,
                                         "view.setBtn_" +
                                         lstrBtnName + "_show(" +
                                         PublicFunction.replace(lstrBtnShowCndt,"&quot;","\"",true) + " ? \"\" : \"none\");",
                                         1);
                }
            }
            super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
        }
        catch(Exception e){
            throw new Exception(e.toString() + " in BusinessBean.outputSetButtonShowMethod");
        }
        finally{
            if(lhtWKF_PRG_BUTTON!=null){
                lhtWKF_PRG_BUTTON.clear();
                lhtWKF_PRG_BUTTON=null;
            }
        }
    }

    /**
     * outputActionForButtonMethod
     *
     * @param pbwrPrgNO BufferedWriter
     */
    private void outputActionForButtonMethod(BufferedWriter pbwrPrgNO,String pstrPrgNO) throws Exception{
        Hashtable<String,Hashtable<String,Object>> lhtWKF_PRG_BUTTON=null;
        String lstrBtnName=null;
        String lstrBtnNameC=null;
        String lstrActionPost = null;

        try{
            lhtWKF_PRG_BUTTON=gqbnDAO.hashtableSQL("select special_name_e,special_name," + DBFunction.getNullToValueSyntax(DBFunction.getDBType(gqbnDAO.getDBAlias()),"click_action_post","'return \"\";'") + " as action_post from wkf_prg_button where prg_no='" + pstrPrgNO + "' and status='" + super.gstrPrgKind + "'");

            if(lhtWKF_PRG_BUTTON==null || lhtWKF_PRG_BUTTON.size()==0){
                return;//沒有設定button
            }

            for(int i=0;i<lhtWKF_PRG_BUTTON.size();i++){
                lstrBtnName = ((Hashtable<String,Object>)lhtWKF_PRG_BUTTON.get(String.valueOf(i))).get("SPECIAL_NAME_E").toString();
                lstrBtnNameC = ((Hashtable<String,Object>)lhtWKF_PRG_BUTTON.get(String.valueOf(i))).get("SPECIAL_NAME").toString();
                lstrActionPost = ((Hashtable<String,Object>)lhtWKF_PRG_BUTTON.get(String.valueOf(i))).get("ACTION_POST").toString();

                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "/**", 2);
                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* 此Method主要是當prgAction的值為" + lstrBtnName + "(" + lstrBtnNameC + ")時所要執行動作的method", 1);
                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*", 1);
                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @param view", 1);
                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @return 字串", 1);
                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*/", 1);

                lstrBtnName = lstrBtnName.substring(0,1).toUpperCase() + lstrBtnName.substring(1);

                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "public String actionFor" + lstrBtnName + "(View view) throws Exception{", 1);
                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, PublicFunction.replace(lstrActionPost,"&quot;","\"",false), 1);
                super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);

            }

        }
        catch(Exception e){
            throw new Exception(e);
        }
        finally{
            if(lhtWKF_PRG_BUTTON!=null){
                lhtWKF_PRG_BUTTON.clear();
                lhtWKF_PRG_BUTTON = null;
            }
        }
    }

    /**
     * outputActionForEndMethod
     *
     * @param pbwrPrgNO BufferedWriter
     */
    private void outputActionForEndMethod(BufferedWriter pbwrPrgNO) throws Exception{
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "/**", 2);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* 此Method主要是當每次page submit or page load時，最後所要執行收尾動作的method", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @param view", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @return 字串", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*/", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "public String actionForEnd(View view) throws Exception{", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "return \"\";", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
    }

    /**
     * outputActionForInitMethod
     *
     * @param pbwrPrgNO BufferedWriter
     */
    private void outputActionForInitMethod(BufferedWriter pbwrPrgNO) throws Exception{
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "/**", 2);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* 此Method主要是當每次page submit or page load時，所要執行起始化動作的method", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @param view", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @return 字串", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*/", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "public String actionForInit(View view) throws Exception{", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "return \"\";", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
    }

    /**
     * outputGetDataMethod
     *
     * @param pbwrPrgNO BufferedWriter
     */
    private void outputGetDataMethod(BufferedWriter pbwrPrgNO) throws Exception{
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "/**", 2);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* 此Method主要是讓 AJAX 呼叫", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @param view", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "* @return 字串", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "*/", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "String getData(View view) throws Exception {", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "if(view.getData_kind()!=null && view.getData_kind().equals(\"\")){", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "//put call method", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "return \"\";", 1);
        super.outputJavaCode(pbwrPrgNO, gstbTabStr, gstrTabChar, "}", 1);
    }


}
